﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ViewQuestion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string qid = Request.Params["qid"];
            QuestionID.Value = qid;

            CmsDataContext db = new CmsDataContext();

            try
            {
                Question question = (from aQ in db.Question
                                     where aQ.ID == qid
                                     select aQ).First();

                Name.Text = question.Name;
                Telphone.Text = question.Phone;
                Address1.Text = string.Format("{0} - {1} - {2}", question.Country, question.Street, question.Village);
                Address2.Text = question.Address;
                QuestionTitle.Text = question.Title;
                Memo.Text = question.Memo;
                Kind.Text = string.Format("{0} - {1} - {2}", question.Kind, question.Subject, question.Country);

                string[] tid = question.Teachers.Split(',');
                foreach (string id in tid)
                {
                    string name = (from aT in db.Teacher where aT.ID == id select aT.Name).First();
                    if (name != null)
                    {
                        if (Teachers.Text.Trim() != "")
                        {
                            Teachers.Text += ",";
                        }

                        Teachers.Text += name;
                    }
                }

                Save.Visible = (question.Verified == null);
            }
            catch
            {
            }
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        CmsDataContext db = new CmsDataContext();
        string qid = QuestionID.Value.Trim();

        try
        {
            Question question = (from aQ in db.Question where aQ.ID == qid select aQ).First();
            question.VerifierID = Toolkit.CurrentUserID;
            question.Verified = DateTime.Now;

            db.SubmitChanges();

            MessageBox.Message = "问题已经通过审核。";
            MessageBox.Location = "./ViewQuestion.aspx?qid=" + question.ID;
        }
        catch (Exception ee)
        {
            MessageBox.Message = "审核时发生错误："+ee.Message;
        }
    }
}